ABAP Select data from SAP table FAGL_QUEUE_LOG 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 FAGL_QUEUE_LOG 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 FAGL_QUEUE_LOG. 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 FAGL_QUEUE_LOG 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_FAGL_QUEUE_LOG TYPE STANDARD TABLE OF FAGL_QUEUE_LOG, WA_FAGL_QUEUE_LOG TYPE FAGL_QUEUE_LOG, 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: <FAGL_QUEUE_LOG> TYPE FAGL_QUEUE_LOG. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_FAGL_QUEUE_LOG. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM FAGL_QUEUE_LOG INTO TABLE IT_FAGL_QUEUE_LOG. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM FAGL_QUEUE_LOG * INTO TABLE @DATA(IT_FAGL_QUEUE_LOG2). *--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_FAGL_QUEUE_LOG INDEX 1 INTO DATA(WA_FAGL_QUEUE_LOG2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_FAGL_QUEUE_LOG ASSIGNING <FAGL_QUEUE_LOG>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<FAGL_QUEUE_LOG>-MANDT = 1.
<FAGL_QUEUE_LOG>-DATASOURCE = 1.
<FAGL_QUEUE_LOG>-RECNR = 1.
<FAGL_QUEUE_LOG>-RYEAR = 1.
<FAGL_QUEUE_LOG>-ACTIV = 1.
ENDLOOP. LOOP AT IT_FAGL_QUEUE_LOG INTO WA_FAGL_QUEUE_LOG. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_FAGL_QUEUE_LOG-RMVCT, sy-vline,
WA_FAGL_QUEUE_LOG-RTCUR, sy-vline,
WA_FAGL_QUEUE_LOG-RUNIT, sy-vline,
WA_FAGL_QUEUE_LOG-AWTYP, sy-vline,
WA_FAGL_QUEUE_LOG-RLDNR, sy-vline,
WA_FAGL_QUEUE_LOG-RRCTY, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FAGL_QUEUE_LOG 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_FAGL_QUEUE_LOG 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_FAGL_QUEUE_LOG INTO WA_FAGL_QUEUE_LOG. *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 RYEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-RYEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-RYEAR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field RUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-RUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-RUNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RLDNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-RLDNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-RLDNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RVERS CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-RVERS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-RVERS.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field LOGSYS CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-LOGSYS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-LOGSYS.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RACCT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-RACCT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-RACCT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field COST_ELEM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-COST_ELEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-COST_ELEM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RCNTR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-RCNTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-RCNTR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PRCTR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-PRCTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-PRCTR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SEGMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-SEGMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-SEGMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SCNTR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-SCNTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-SCNTR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PPRCTR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-PPRCTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-PPRCTR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RASSC CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-RASSC IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-RASSC.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PSEGMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-PSEGMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-PSEGMENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field QUANUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-QUANUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-QUANUNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit PERI7, internal->external for field FISCPER CALL FUNCTION 'CONVERSION_EXIT_PERI7_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-FISCPER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-FISCPER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC172, internal->external for field BALANCE CALL FUNCTION 'CONVERSION_EXIT_AC172_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-BALANCE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-BALANCE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC172, internal->external for field DEBIT CALL FUNCTION 'CONVERSION_EXIT_AC172_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-DEBIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-DEBIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC172, internal->external for field CREDIT CALL FUNCTION 'CONVERSION_EXIT_AC172_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-CREDIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-CREDIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit AC172, internal->external for field TURNOVER CALL FUNCTION 'CONVERSION_EXIT_AC172_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-TURNOVER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-TURNOVER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field ADQUANUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-ADQUANUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-ADQUANUNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RCOMP CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-RCOMP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-RCOMP.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field RPRCTR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-RPRCTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-RPRCTR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SPRCTR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAGL_QUEUE_LOG-SPRCTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAGL_QUEUE_LOG-SPRCTR.
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_FAGL_QUEUE_LOG_STR,
MANDT TYPE STRING,
DATASOURCE TYPE STRING,
RECNR TYPE STRING,
RYEAR TYPE STRING,
ACTIV TYPE STRING,
RMVCT TYPE STRING,
RTCUR TYPE STRING,
RUNIT TYPE STRING,
AWTYP TYPE STRING,
RLDNR TYPE STRING,
RRCTY TYPE STRING,
RVERS TYPE STRING,
LOGSYS TYPE STRING,
RACCT TYPE STRING,
COST_ELEM TYPE STRING,
RBUKRS TYPE STRING,
RCNTR TYPE STRING,
PRCTR TYPE STRING,
RFAREA TYPE STRING,
RBUSA TYPE STRING,
KOKRS TYPE STRING,
SEGMENT TYPE STRING,
SCNTR TYPE STRING,
PPRCTR TYPE STRING,
SFAREA TYPE STRING,
SBUSA TYPE STRING,
RASSC TYPE STRING,
PSEGMENT TYPE STRING,
TIMESTAMP TYPE STRING,
QUANUNIT TYPE STRING,
VALUETYPE TYPE STRING,
CURTYPE TYPE STRING,
FISCPER TYPE STRING,
FISCVAR TYPE STRING,
CHARTACCTS TYPE STRING,
UPMOD TYPE STRING,
VALUTYP TYPE STRING,
CURRUNIT TYPE STRING,
BALANCE TYPE STRING,
DEBIT TYPE STRING,
CREDIT TYPE STRING,
TURNOVER TYPE STRING,
QUANTITY TYPE STRING,
ADQUANUNIT TYPE STRING,
ADQUANTITY TYPE STRING,
CPUDT TYPE STRING,
CPUTM TYPE STRING,
RCOMP TYPE STRING,
RPRCTR TYPE STRING,
SPRCTR TYPE STRING,
USNAM TYPE STRING,
REQUNR TYPE STRING,END OF T_EKKO_STR. DATA: WA_FAGL_QUEUE_LOG_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_FAGL_QUEUE_LOG_STR-MANDT sy-vline
WA_FAGL_QUEUE_LOG_STR-DATASOURCE sy-vline
WA_FAGL_QUEUE_LOG_STR-RECNR sy-vline
WA_FAGL_QUEUE_LOG_STR-RYEAR sy-vline
WA_FAGL_QUEUE_LOG_STR-ACTIV sy-vline
WA_FAGL_QUEUE_LOG_STR-RMVCT sy-vline
WA_FAGL_QUEUE_LOG_STR-RTCUR sy-vline
WA_FAGL_QUEUE_LOG_STR-RUNIT sy-vline
WA_FAGL_QUEUE_LOG_STR-AWTYP sy-vline
WA_FAGL_QUEUE_LOG_STR-RLDNR sy-vline
WA_FAGL_QUEUE_LOG_STR-RRCTY sy-vline
WA_FAGL_QUEUE_LOG_STR-RVERS sy-vline
WA_FAGL_QUEUE_LOG_STR-LOGSYS sy-vline
WA_FAGL_QUEUE_LOG_STR-RACCT sy-vline
WA_FAGL_QUEUE_LOG_STR-COST_ELEM sy-vline
WA_FAGL_QUEUE_LOG_STR-RBUKRS sy-vline
WA_FAGL_QUEUE_LOG_STR-RCNTR sy-vline
WA_FAGL_QUEUE_LOG_STR-PRCTR sy-vline
WA_FAGL_QUEUE_LOG_STR-RFAREA sy-vline
WA_FAGL_QUEUE_LOG_STR-RBUSA sy-vline
WA_FAGL_QUEUE_LOG_STR-KOKRS sy-vline
WA_FAGL_QUEUE_LOG_STR-SEGMENT sy-vline
WA_FAGL_QUEUE_LOG_STR-SCNTR sy-vline
WA_FAGL_QUEUE_LOG_STR-PPRCTR sy-vline
WA_FAGL_QUEUE_LOG_STR-SFAREA sy-vline
WA_FAGL_QUEUE_LOG_STR-SBUSA sy-vline
WA_FAGL_QUEUE_LOG_STR-RASSC sy-vline
WA_FAGL_QUEUE_LOG_STR-PSEGMENT sy-vline
WA_FAGL_QUEUE_LOG_STR-TIMESTAMP sy-vline
WA_FAGL_QUEUE_LOG_STR-QUANUNIT sy-vline
WA_FAGL_QUEUE_LOG_STR-VALUETYPE sy-vline
WA_FAGL_QUEUE_LOG_STR-CURTYPE sy-vline
WA_FAGL_QUEUE_LOG_STR-FISCPER sy-vline
WA_FAGL_QUEUE_LOG_STR-FISCVAR sy-vline
WA_FAGL_QUEUE_LOG_STR-CHARTACCTS sy-vline
WA_FAGL_QUEUE_LOG_STR-UPMOD sy-vline
WA_FAGL_QUEUE_LOG_STR-VALUTYP sy-vline
WA_FAGL_QUEUE_LOG_STR-CURRUNIT sy-vline
WA_FAGL_QUEUE_LOG_STR-BALANCE sy-vline
WA_FAGL_QUEUE_LOG_STR-DEBIT sy-vline
WA_FAGL_QUEUE_LOG_STR-CREDIT sy-vline
WA_FAGL_QUEUE_LOG_STR-TURNOVER sy-vline
WA_FAGL_QUEUE_LOG_STR-QUANTITY sy-vline
WA_FAGL_QUEUE_LOG_STR-ADQUANUNIT sy-vline
WA_FAGL_QUEUE_LOG_STR-ADQUANTITY sy-vline
WA_FAGL_QUEUE_LOG_STR-CPUDT sy-vline
WA_FAGL_QUEUE_LOG_STR-CPUTM sy-vline
WA_FAGL_QUEUE_LOG_STR-RCOMP sy-vline
WA_FAGL_QUEUE_LOG_STR-RPRCTR sy-vline
WA_FAGL_QUEUE_LOG_STR-SPRCTR sy-vline
WA_FAGL_QUEUE_LOG_STR-USNAM sy-vline
WA_FAGL_QUEUE_LOG_STR-REQUNR sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.