ABAP Select data from SAP table AVIAJRECINDX into internal table
Get Example source ABAP code based on a different SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP AVIAJRECINDX table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to AVIAJRECINDX. See here for more generic Select statement tips.
Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.
There is also a full declaration of the AVIAJRECINDX table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.
DATA: IT_AVIAJRECINDX TYPE STANDARD TABLE OF AVIAJRECINDX, WA_AVIAJRECINDX TYPE AVIAJRECINDX, GD_STR TYPE STRING. DATA: lo_typedescr type REF TO cl_abap_typedescr. DATA: lv_fieldname type fieldname. FIELD-SYMBOLS: <FIELD> TYPE any. FIELD-SYMBOLS: <AVIAJRECINDX> TYPE AVIAJRECINDX. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_AVIAJRECINDX. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM AVIAJRECINDX INTO TABLE IT_AVIAJRECINDX. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM AVIAJRECINDX * INTO TABLE @DATA(IT_AVIAJRECINDX2). *--Further methods of using ABAP code to select data from SAP database tables *You can also declare the header/work area using the in-line DATA declaration method READ TABLE IT_AVIAJRECINDX INDEX 1 INTO DATA(WA_AVIAJRECINDX2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_AVIAJRECINDX ASSIGNING <AVIAJRECINDX>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<AVIAJRECINDX>-MANDT = 1.
<AVIAJRECINDX>-RECINDXGUID = 1.
<AVIAJRECINDX>-PROCESSGUID = 1.
<AVIAJRECINDX>-INTRENO = 1.
<AVIAJRECINDX>-ADJMINDEXBASE = 1.
ENDLOOP. LOOP AT IT_AVIAJRECINDX INTO WA_AVIAJRECINDX. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_AVIAJRECINDX-ADJMINDEXDATE, sy-vline,
WA_AVIAJRECINDX-INDEXSERIES, sy-vline,
WA_AVIAJRECINDX-INDEXBASEYEAR, sy-vline,
WA_AVIAJRECINDX-INDEXBASEACT, sy-vline,
WA_AVIAJRECINDX-FIRSTINDEXBASE, sy-vline,
WA_AVIAJRECINDX-FIRSTINDEXDATE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_AVIAJRECINDX you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_AVIAJRECINDX TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_AVIAJRECINDX INTO WA_AVIAJRECINDX. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
*Conversion exit GJAHR, internal->external for field INDEXBASEYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_AVIAJRECINDX-INDEXBASEYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_AVIAJRECINDX-INDEXBASEYEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field RB_INDEXBASEYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_AVIAJRECINDX-RB_INDEXBASEYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_AVIAJRECINDX-RB_INDEXBASEYEAR.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_AVIAJRECINDX_STR,
MANDT TYPE STRING,
RECINDXGUID TYPE STRING,
PROCESSGUID TYPE STRING,
INTRENO TYPE STRING,
ADJMINDEXBASE TYPE STRING,
ADJMINDEXDATE TYPE STRING,
INDEXSERIES TYPE STRING,
INDEXBASEYEAR TYPE STRING,
INDEXBASEACT TYPE STRING,
FIRSTINDEXBASE TYPE STRING,
FIRSTINDEXDATE TYPE STRING,
INDEXCHGPERLAST TYPE STRING,
INDEXCHGPOILAST TYPE STRING,
IGNOREFOLLOWADJM TYPE STRING,
INDEXCHGPERFIRST TYPE STRING,
INDEXCHGPOIFIRST TYPE STRING,
UNITPRICEFIRST TYPE STRING,
RB_INDEXSERIES TYPE STRING,
RB_INDEXBASEYEAR TYPE STRING,
RB_CHGPOINTS TYPE STRING,
RB_CONSPERCENT TYPE STRING,
RB_CONSPOINTS TYPE STRING,
RB_PERCENT_DOWN TYPE STRING,
RB_PERCENT_UP TYPE STRING,
RB_POINTS_DOWN TYPE STRING,
RB_POINTS_UP TYPE STRING,
RB_POIORG_DOWN TYPE STRING,
RB_POIORG_UP TYPE STRING,
RB_CHG_BEFORE TYPE STRING,
RB_CHG_AFTER TYPE STRING,
RB_BORDER_DOWN TYPE STRING,
RB_BORDER_UP TYPE STRING,
RB_BORDER_CDOWN TYPE STRING,
RB_BORDER_CUP TYPE STRING,
KZ TYPE STRING,END OF T_EKKO_STR. DATA: WA_AVIAJRECINDX_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_AVIAJRECINDX_STR-MANDT sy-vline
WA_AVIAJRECINDX_STR-RECINDXGUID sy-vline
WA_AVIAJRECINDX_STR-PROCESSGUID sy-vline
WA_AVIAJRECINDX_STR-INTRENO sy-vline
WA_AVIAJRECINDX_STR-ADJMINDEXBASE sy-vline
WA_AVIAJRECINDX_STR-ADJMINDEXDATE sy-vline
WA_AVIAJRECINDX_STR-INDEXSERIES sy-vline
WA_AVIAJRECINDX_STR-INDEXBASEYEAR sy-vline
WA_AVIAJRECINDX_STR-INDEXBASEACT sy-vline
WA_AVIAJRECINDX_STR-FIRSTINDEXBASE sy-vline
WA_AVIAJRECINDX_STR-FIRSTINDEXDATE sy-vline
WA_AVIAJRECINDX_STR-INDEXCHGPERLAST sy-vline
WA_AVIAJRECINDX_STR-INDEXCHGPOILAST sy-vline
WA_AVIAJRECINDX_STR-IGNOREFOLLOWADJM sy-vline
WA_AVIAJRECINDX_STR-INDEXCHGPERFIRST sy-vline
WA_AVIAJRECINDX_STR-INDEXCHGPOIFIRST sy-vline
WA_AVIAJRECINDX_STR-UNITPRICEFIRST sy-vline
WA_AVIAJRECINDX_STR-RB_INDEXSERIES sy-vline
WA_AVIAJRECINDX_STR-RB_INDEXBASEYEAR sy-vline
WA_AVIAJRECINDX_STR-RB_CHGPOINTS sy-vline
WA_AVIAJRECINDX_STR-RB_CONSPERCENT sy-vline
WA_AVIAJRECINDX_STR-RB_CONSPOINTS sy-vline
WA_AVIAJRECINDX_STR-RB_PERCENT_DOWN sy-vline
WA_AVIAJRECINDX_STR-RB_PERCENT_UP sy-vline
WA_AVIAJRECINDX_STR-RB_POINTS_DOWN sy-vline
WA_AVIAJRECINDX_STR-RB_POINTS_UP sy-vline
WA_AVIAJRECINDX_STR-RB_POIORG_DOWN sy-vline
WA_AVIAJRECINDX_STR-RB_POIORG_UP sy-vline
WA_AVIAJRECINDX_STR-RB_CHG_BEFORE sy-vline
WA_AVIAJRECINDX_STR-RB_CHG_AFTER sy-vline
WA_AVIAJRECINDX_STR-RB_BORDER_DOWN sy-vline
WA_AVIAJRECINDX_STR-RB_BORDER_UP sy-vline
WA_AVIAJRECINDX_STR-RB_BORDER_CDOWN sy-vline
WA_AVIAJRECINDX_STR-RB_BORDER_CUP sy-vline
WA_AVIAJRECINDX_STR-KZ sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.