Tuesday, April 19, 2011

General

Dynamic SQL

DATA: BEGIN OF w_m,
               matnr like mara-matnr,
               mtart LIKE mara-mtart,
            END OF w_m.

DATA: i_m LIKE STANDARD TABLE OF w_m WITH HEADER LINE.

DATA: column_syntax TYPE string,
      cond_syntax TYPE string.

CONCATENATE 'MATNR' 'MTART' INTO column_syntax SEPARATED BY space.

CONCATENATE 'MTART' 'IN S_MTART' INTO cond_syntax SEPARATED BY space.


select  (column_syntax) into corresponding fields of table i_m
  From mara
  UP TO 10 ROWS
  Where (cond_syntax).

Difference between “ ‘ ” and “ ` ” in ABAP

A basic difference: still I find that most of the programmer hardly uses string literal. String literal is generally a forgotten case.
A character sequence within single quote characters (’) is a char literal, while within (`) is a string literal. That is especially important for trailing spaces: a string literal preserves the trailing space while a char literal ignores them.
This can be best understood by the following example:

DATA v_char TYPE c LENGTH 32.
v_char = 'This is a'.
CONCATENATE v_char 'text   ' INTO v_char SEPARATED BY space.
*" v_char would be "This is a text"
CONCATENATE v_char `text   ` INTO v_char SEPARATED BY space.
*" v_char would be "This is a text   "

Field Symbol

CONSTANTS: c_ydrseg(18) TYPE c VALUE '(SAPLMR1M)YDRSEG[]'.

DATA: wa_drseg TYPE mmcr_drseg.
CLEAR wa_drseg.

FIELD-SYMBOLS: <fs_ydrseg> TYPE table.

ASSIGN (c_ydrseg) TO <fs_ydrseg>.

CLEAR lt_drseg.REFRESH lt_drseg.
lt_drseg[] = <fs_ydrseg>.

IF NOT <fs_ydrseg>[] IS INITIAL.

  LOOP AT lt_drseg INTO wa_drseg.
    * do something with EREKZ
  ENDLOOP.
ENDIF.

____________________________________________
DATA  : l_stack(50)  TYPE c.

FIELD-SYMBOLS : <fs1> TYPE ANY TABLE.

MOVE '(SAPLV09A)GVT_LOCAL_MEMORY-XVBPA[]' TO l_stack.

ASSIGN (l_stack) TO <fs1>.
IF sy-subrc = 0.
   ..................................
ENDIF.

No comments:

Post a Comment