ABAP Select data from SAP table FAC_OPP_S_SCHEDULED_JOBS 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 FAC_OPP_S_SCHEDULED_JOBS 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 FAC_OPP_S_SCHEDULED_JOBS. 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 FAC_OPP_S_SCHEDULED_JOBS 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_FAC_OPP_S_SCHEDULED_JOBS TYPE STANDARD TABLE OF FAC_OPP_S_SCHEDULED_JOBS, WA_FAC_OPP_S_SCHEDULED_JOBS TYPE FAC_OPP_S_SCHEDULED_JOBS, 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: <FAC_OPP_S_SCHEDULED_JOBS> TYPE FAC_OPP_S_SCHEDULED_JOBS. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_FAC_OPP_S_SCHEDULED_JOBS. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM FAC_OPP_S_SCHEDULED_JOBS INTO TABLE IT_FAC_OPP_S_SCHEDULED_JOBS. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM FAC_OPP_S_SCHEDULED_JOBS * INTO TABLE @DATA(IT_FAC_OPP_S_SCHEDULED_JOBS2). *--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_FAC_OPP_S_SCHEDULED_JOBS INDEX 1 INTO DATA(WA_FAC_OPP_S_SCHEDULED_JOBS2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_FAC_OPP_S_SCHEDULED_JOBS ASSIGNING <FAC_OPP_S_SCHEDULED_JOBS>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<FAC_OPP_S_SCHEDULED_JOBS>-JOB_NAME = 1.
<FAC_OPP_S_SCHEDULED_JOBS>-JOB_COUNT = 1.
<FAC_OPP_S_SCHEDULED_JOBS>-SCHEDULE_ID = 1.
<FAC_OPP_S_SCHEDULED_JOBS>-JOB_TYPE = 1.
<FAC_OPP_S_SCHEDULED_JOBS>-ACTION_IDENTIFIER = 1.
ENDLOOP. LOOP AT IT_FAC_OPP_S_SCHEDULED_JOBS INTO WA_FAC_OPP_S_SCHEDULED_JOBS. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_FAC_OPP_S_SCHEDULED_JOBS-RRCTY, sy-vline,
WA_FAC_OPP_S_SCHEDULED_JOBS-OPVAR, sy-vline,
WA_FAC_OPP_S_SCHEDULED_JOBS-OPVTX, sy-vline,
WA_FAC_OPP_S_SCHEDULED_JOBS-MKOAR, sy-vline,
WA_FAC_OPP_S_SCHEDULED_JOBS-DDTEXT, sy-vline,
WA_FAC_OPP_S_SCHEDULED_JOBS-BKONT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FAC_OPP_S_SCHEDULED_JOBS 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_FAC_OPP_S_SCHEDULED_JOBS 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_FAC_OPP_S_SCHEDULED_JOBS INTO WA_FAC_OPP_S_SCHEDULED_JOBS. *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 ALPHA, internal->external for field BKONT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAC_OPP_S_SCHEDULED_JOBS-BKONT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAC_OPP_S_SCHEDULED_JOBS-BKONT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field VKONT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FAC_OPP_S_SCHEDULED_JOBS-VKONT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAC_OPP_S_SCHEDULED_JOBS-VKONT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit GJAHR, internal->external for field START_YEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_FAC_OPP_S_SCHEDULED_JOBS-START_YEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FAC_OPP_S_SCHEDULED_JOBS-START_YEAR.
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_FAC_OPP_S_SCHEDULED_JOBS_STR,
JOB_NAME TYPE STRING,
JOB_COUNT TYPE STRING,
SCHEDULE_ID TYPE STRING,
JOB_TYPE TYPE STRING,
ACTION_IDENTIFIER TYPE STRING,
RRCTY TYPE STRING,
OPVAR TYPE STRING,
OPVTX TYPE STRING,
MKOAR TYPE STRING,
DDTEXT TYPE STRING,
BKONT TYPE STRING,
VKONT TYPE STRING,
PERIV TYPE STRING,
ANZBP TYPE STRING,
ANZSP TYPE STRING,
FRYE1_NEXT TYPE STRING,
FRPE1_NEXT TYPE STRING,
TOYE1_NEXT TYPE STRING,
TOPE1_NEXT TYPE STRING,
PERIODIC_ACTION2 TYPE STRING,
FRYE2_NEXT TYPE STRING,
FRPE2_NEXT TYPE STRING,
TOYE2_NEXT TYPE STRING,
TOPE2_NEXT TYPE STRING,
PERIODIC_ACTION3 TYPE STRING,
FRYE3_NEXT TYPE STRING,
FRPE3_NEXT TYPE STRING,
TOYE3_NEXT TYPE STRING,
TOPE3_NEXT TYPE STRING,
PERIODIC_ACTION TYPE STRING,
FRPE_NEXT TYPE STRING,
TOPE_NEXT TYPE STRING,
FRYE_NEXT TYPE STRING,
TOYE_NEXT TYPE STRING,
START_DAY TYPE STRING,
START_TIME TYPE STRING,
START_END_MONTH TYPE STRING,
START_YEAR TYPE STRING,
START_DATE TYPE STRING,
TIME_PERIOD TYPE STRING,
TIME_ZONE TYPE STRING,
TIME_ZONE_DESCR TYPE STRING,
TIME_ZONE_UTC_DIFFERENCE TYPE STRING,
TIME_ZONE_UTC_SIGN TYPE STRING,
JOB_RUN_TIME TYPE STRING,
JOB_RUN_TIME_SERVER TYPE STRING,
TIME_ZONE_SERVER TYPE STRING,
FACTORY_CALENDAR TYPE STRING,
FACTORY_CALENDAR_DESCR TYPE STRING,
ACCOUNT_RANGE TYPE STRING,
FLAG_MULTI_ACCOUNT_RANGE TYPE STRING,
CREATE_BY TYPE STRING,
CREATE_AT TYPE STRING,
HAS_PPV_CHANGE_AUTH TYPE STRING,
FLAG_CLOSE_ADJUST_PERIODS TYPE STRING,
FLAG_CLOSE_COFI TYPE STRING,
FLAG_KEEP_AUTH_GROUP TYPE STRING,
FLAG_RESET_AUTH_GROUP TYPE STRING,
FLAG_CHANGE_AUTH_GROUP TYPE STRING,
AUTH_GROUP TYPE STRING,
ACTION_AUTH_GROUP TYPE STRING,END OF T_EKKO_STR. DATA: WA_FAC_OPP_S_SCHEDULED_JOBS_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_FAC_OPP_S_SCHEDULED_JOBS_STR-JOB_NAME sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-JOB_COUNT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-SCHEDULE_ID sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-JOB_TYPE sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-ACTION_IDENTIFIER sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-RRCTY sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-OPVAR sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-OPVTX sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-MKOAR sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-DDTEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-BKONT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-VKONT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-PERIV sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-ANZBP sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-ANZSP sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FRYE1_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FRPE1_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-TOYE1_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-TOPE1_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-PERIODIC_ACTION2 sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FRYE2_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FRPE2_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-TOYE2_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-TOPE2_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-PERIODIC_ACTION3 sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FRYE3_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FRPE3_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-TOYE3_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-TOPE3_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-PERIODIC_ACTION sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FRPE_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-TOPE_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FRYE_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-TOYE_NEXT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-START_DAY sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-START_TIME sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-START_END_MONTH sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-START_YEAR sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-START_DATE sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-TIME_PERIOD sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-TIME_ZONE sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-TIME_ZONE_DESCR sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-TIME_ZONE_UTC_DIFFERENCE sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-TIME_ZONE_UTC_SIGN sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-JOB_RUN_TIME sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-JOB_RUN_TIME_SERVER sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-TIME_ZONE_SERVER sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FACTORY_CALENDAR sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FACTORY_CALENDAR_DESCR sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-ACCOUNT_RANGE sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FLAG_MULTI_ACCOUNT_RANGE sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-CREATE_BY sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-CREATE_AT sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-HAS_PPV_CHANGE_AUTH sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FLAG_CLOSE_ADJUST_PERIODS sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FLAG_CLOSE_COFI sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FLAG_KEEP_AUTH_GROUP sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FLAG_RESET_AUTH_GROUP sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-FLAG_CHANGE_AUTH_GROUP sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-AUTH_GROUP sy-vline
WA_FAC_OPP_S_SCHEDULED_JOBS_STR-ACTION_AUTH_GROUP sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.