SAP ABAP 740

From SapWiki
Revision as of 17:47, 26 March 2020 by WikiSysop (talk | contribs)

Ejemplos

VALUE

types ty_ra type RANGE OF vbak-auart.
data(ra_auart) = VALUE ty_ra(
                              ( low = 'Z1' sign = 'I' option = 'EQ' )
                              ( low = 'Z2' sign = 'I' option = 'EQ' )
                            ).
 select vbeln into table @data(LT_vbeln) from vbak where auart in @ra_auart.
DATA itab TYPE RANGE OF i. 
itab = VALUE #( sign = 'I'  option = 'BT' ( low = 1  high = 10 ) 
                                         ( low = 21 high = 30 ) 
                                         ( low = 41 high = 50 ) 
                           option = 'GE' ( low = 61 )  ).
data ra_ktart TYPE RANGE OF p2006-ktart.
CASE lw_solicitudes-subty.
  WHEN '0100'.
    ra_ktart = VALUE #( ( low = '01' sign = 'I' option = 'EQ' )
                           ( low = '02' sign = 'I' option = 'EQ' )                     ).
  WHEN '0300' OR '0301' OR '0309'.
    ra_ktart = VALUE #( ( low = '17' sign = 'I' option = 'EQ' ) ).
   WHEN '0901'.
     ra_ktart = VALUE #( ( low = '10' sign = 'I' option = 'EQ' ) ).
ENDCASE.

Manejo de strings

character_string = |{ a_numeric_variable }|.
character_string = |This resulted in return code { sy-subrc }|.
LO_OBJECT->STRING2XML( |{ converted_xml }{ xml_row-row_close_tag }| ).
v_var1 = 'Esto es'.
v_var2 = 'un'.
v_var3 = 'String'.
lv_result = v_var1 && v_var2 && v_var3.
[WIDTH     = len]
[ALIGN     = LEFT|RIGHT|CENTER|(val)]
[PAD       = c]
[CASE      = RAW|UPPER|LOWER|(val)]
[SIGN      = LEFT|LEFTPLUS|LEFTSPACE|RIGHT|RIGHTPLUS|RIGHTSPACE|(val)]
[EXPONENT  = exp]
[DECIMALS  = dec]
[ZERO      = YES|NO|(val)]
[XSD       = YES|NO|(val)]
[STYLE     =  SIMPLE|SIGN_AS_POSTFIX|SCALE_PRESERVING
             |SCIENTIFIC|SCIENTIFIC_WITH_LEADING_ZERO
             |SCALE_PRESERVING_SCIENTIFIC|ENGINEERING
             |(val)]
[CURRENCY  = cur]
[NUMBER    = RAW|USER|ENVIRONMENT|(val)]
[DATE      = RAW|ISO|USER|ENVIRONMENT|(val)]
[TIME      = RAW|ISO|USER|ENVIRONMENT|(val)]
[TIMESTAMP = SPACE|ISO|USER|ENVIRONMENT|(val)]
[TIMEZONE  = tz]
[COUNTRY   = cty] ...

l_dir = |including a \{ bracket|.
l_dir = |c:\\temp|.  "c:\temp'
TRY.
  WRITE: /   |string|.
  WRITE: /   |{ my_variable }|.
  WRITE: /   |i'm a { my_variable }!|.
  WRITE: /   |i'm number { my_number * 10 }!| .
  WRITE: /   |client 000 is called: | &&
             |{ clients[ mandt = '000' ]-mtext }|.
  WRITE: /   |i'm going to be in upper case: | &&
             |{ my_variable CASE = UPPER }|.
  WRITE: /   |function and formatting:| &&
             | date raw - { my_string->date( ) DATE = RAW }| &&
             | date iso - { my_string->date( ) DATE = ISO }|.
  CATCH cx_root.
ENDTRY.

CONV

data: l_dir type char200.
l_dir = 'c:\temp'.
data(l_resp) =  cl_gui_frontend_services=>directory_exist( DIRECTORY = CONV #( l_dir ) ).

SWITCH

DATA l_flag TYPE flag.
DATA(l_status) = SWITCH #( l_flag
                             WHEN 'X' THEN 'OK'
                             ELSE 'Error'
                         ).
DATA(l_number) = SWITCH string( sy-index WHEN 1 THEN 'uno'
                                      WHEN 2 THEN 'dos'
                                      WHEN 3 THEN 'tres'
                                      else 'nada' ).