I want to extract all bkpf's fields into a tab delimited file in the background.
How can we do it?
Thanks in advance
Elias
PS: The code of the program that the Perform exec_in_bckgr doesn't understand the change of the Checkbox in SUBMIT WITH p_bckgr = space.
REPORT zfor_get_bkrf_bseg4.
TABLES: bkpf.
DATA: it_bkpf TYPE STANDARD TABLE OF bkpf,
ls_bkpf TYPE bkpf,
i_filename LIKE rlgrap-filename.
FIELD-SYMBOLS: <fs_field>.
SELECTION-SCREEN BEGIN OF BLOCK selection WITH FRAME TITLE text-s01.
SELECT-OPTIONS: so_bukrs FOR bkpf-bukrs,
so_budat FOR bkpf-budat OBLIGATORY.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN ULINE.
PARAMETERS: p_bkgrd AS CHECKBOX USER-COMMAND check DEFAULT 'X'.
" File Path on Application Server or on Local PC according to p_bkgrd
PARAMETERS: p_paths TYPE btcxpgpar DEFAULT '/tmp' MODIF ID sg1.
SELECTION-SCREEN END OF BLOCK selection.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_paths.
DATA: c_fnh_mask TYPE dxfields-filemask VALUE '*',
search_dir TYPE dxfields-longpath .
CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = search_dir
filemask = c_fnh_mask
IMPORTING
serverfile = p_paths
EXCEPTIONS
canceled_by_user = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
START-OF-SELECTION.
IF p_bkgrd = 'X'.
PERFORM exec_in_bckgr.
ELSE.
PERFORM get_data.
PERFORM download_tables_paths.
ENDIF.
END-OF-SELECTION.
WRITE: i_filename , ' is created' .
FORM get_data .
SELECT * INTO TABLE it_bkpf
FROM bkpf
WHERE bukrs IN so_bukrs AND
budat IN so_budat.
ENDFORM. " GET_DATA
FORM download_tables_paths .
DATA:lv_line(4096) TYPE c,
lv_field_type(10) TYPE c,
lv_field_text(10) TYPE c.
" Build FineName
CONCATENATE p_paths '/' 'BKPF' sy-datum sy-uzeit '.txt'
INTO i_filename.
REPLACE ALL OCCURRENCES OF '//' IN i_filename WITH '/'.
* Process further only if found some data
IF NOT it_bkpf[] IS INITIAL.
" Open file for Output
OPEN DATASET i_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0 .
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
LOOP AT it_bkpf INTO ls_bkpf.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE ls_bkpf TO <fs_field>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF lv_line IS INITIAL.
lv_line = <fs_field>.
ELSE.
DESCRIBE FIELD <fs_field> TYPE lv_field_type.
IF lv_field_type = 'P' OR lv_field_type = 'I'.
lv_field_text = <fs_field>.
CONDENSE lv_field_text NO-GAPS.
CONCATENATE lv_line '|' lv_field_text INTO lv_line.
ELSE.
CONCATENATE lv_line '|' <fs_field> INTO lv_line.
ENDIF.
ENDIF.
ENDDO.
TRANSFER lv_line TO i_filename.
CLEAR: lv_line.
ENDLOOP.
ENDIF.
CLOSE DATASET i_filename.
ENDIF.
ENDFORM.
FORM exec_in_bckgr .
DATA: jobname1 TYPE tbtcjob-jobname,
jobcount1 TYPE tbtcjob-jobcount.
jobname1 = 'ZFOR_GET_BKRF_BSEG2'.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = jobname1
IMPORTING
jobcount = jobcount1
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc NE 0.
MESSAGE s368(00) WITH 'Error Creating Job'
sy-subrc.
EXIT.
ENDIF.
SUBMIT zfor_get_bkrf_bseg2
WITH so_bukrs IN so_bukrs
WITH so_budat IN so_budat
WITH p_bckgr = space
WITH p_paths = p_paths
VIA JOB jobname1 NUMBER jobcount1
AND RETURN.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = jobcount1
jobname = jobname1
* sdlstrtdt = sdate
* sdlstrttm = stime
* strtimmed = 'X' " Start immediately
EXCEPTIONS
invalid_startdate = 1
jobname_missing = 2
job_close_failed = 3
job_nosteps = 4
job_notex = 5
lock_failed = 6
OTHERS = 7.
IF sy-subrc > 0.
MESSAGE s368(00) WITH 'Closing Job Failed'
sy-subrc.
EXIT.
ENDIF.
ENDFORM.
The program is too simple and I do not understand why the site is asking me to add more comments.
OK, if I enable the strtimmed = 'X' in CALL FUNCTION 'JOB_CLOSE', then the program is creating jobs continuously and I have to kill it through SM50.
If I disable the STRTIMED then it create a job as SCHEDULE. I run it as Immediate and it creates and run a job without creating a file while in foreground the program is working perfect.
So my question is: Is this code OK for SAP ECC6?
Thanks in advance
Elias
The following code could be a solution.
Select your lines from BSEG in 10.000 packages, bring it in csv-format and transfer it into the open file.
DO.
SELECT * FROM bseg UP TO 10000 ROWS
INTO TABLE #DATA(lt_bseg)
WHERE bukrs = '0001'.
IF sy-subrc <> 0.
EXIT.
ENDIF.
OPEN DATASET filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT lt_bseg INTO DATA(ls_bseg).
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE ls_bseg TO FIELD-SYMBOL(<fs_field>).
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF line IS INITIAL.
line = <fs_field>.
ELSE.
line = line && ';' && <fs_field>.
ENDIF.
TRANSFER line TO filename.
CLEAR: line.
ENDDO.
ENDLOOP.
ENDDO.
CLOSE DATASET filename.
Finally someone told me what was wrong in my code. I missed a D in WITH p_bckgr = space.
I thought that if it is wrong the SAP will display an error, but this was a wrong thought.
So the correct is WITH p_bkgrd = space.
Thanks all
Related
Doing a project for a qbasic class, and i need the 1st row to ask for input i.e. " Enter projected depletion rate: ", after doing that it will run a loop under it, wherein i need it to print another input statement on that same 1st row, " Enter another projected depletion rate or 0 to quit :" the issue i'm having is that if i use LOCATE it will print the next results of the loop directly under that statement when id like it to print below the last results in the list, at the lowest unused space, and it doesn't clear the top row of old text. I know part of it is that the LOCATE is getting repeated because of the loop but i'm genuinely stuck. sorry for format i'm new :)
CLS
DIM percent AS DOUBLE
DIM ozLevel AS DOUBLE
DIM counter AS INTEGER
DIM change AS DOUBLE
INPUT "enter a projected depletion rate, or 0 to quit: ", percent
PRINT
PRINT TAB(2); "Loss"; TAB(17); "Final Ozone"
PRINT TAB(2); "Rate"; TAB(10); "Years"; TAB(17); "Concentration"
change = (percent / 100)
DO WHILE percent <> 0
counter = 0
ozLevel = 450
DO UNTIL ozLevel < 200
counter = counter + 1
ozLevel = ozLevel - (ozLevel * change)
LOOP
PRINT USING "##.##%"; TAB(2); percent;
PRINT TAB(10); counter;
PRINT USING "###.##"; TAB(17); ozLevel;
LOCATE 1, 1
INPUT "enter new projection: ", percent
change = (percent / 100)
LOOP
LOCATE 1, 35
PRINT "DONE"
END
QBasic has the CRSLIN function that tells you where the cursor is.
Make sure that printing the 3rd result does a carriage return and linefeed. Just remove the ;
Now store the index to the next available row in a suitable variable like TableRow.
Input as before on the 1st row of the screen.
Position the cursor on the next available row using this variable after each following input.
...
PRINT USING "###.##"; TAB(17); ozLevel
tablerow = CRSLIN
LOCATE 1, 1
INPUT "enter new projection: ", percent
change = (percent / 100)
LOCATE tablerow, 1
LOOP
...
I am trying to display 2 row multi heading in an alv grid display where each main heading should occupy 2 sub-headings as follows:
REPORT zsam7.
TYPE-POOLS: slis. " SLIS contains all the ALV data
TYPES: BEGIN OF ty_report,
jan_deb TYPE umxxs,
jan_cred TYPE umxxh,
feb_deb TYPE umxxs,
feb_cred TYPE umxxh,
END OF ty_report,
tt_report TYPE TABLE OF ty_report.
DATA: lt_report TYPE tt_report WITH HEADER LINE,
wa TYPE ty_report,
lfc1_table TYPE STANDARD TABLE OF lfc1,
repid TYPE sy-repid,
wa_deb TYPE saldv,
wa_cred TYPE saldv,
it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
x_events TYPE slis_alv_event,
it_events TYPE slis_t_event,
l_layout TYPE slis_layout_alv.
FIELD-SYMBOLS: <fs_rep> LIKE LINE OF lt_report,
<fs_rep1> LIKE LINE OF lfc1_table.
SELECT * FROM lfc1 INTO CORRESPONDING FIELDS OF TABLE lfc1_table WHERE bukrs = '1000' AND gjahr = 2003.
LOOP AT lfc1_table ASSIGNING <fs_rep1>.
APPEND INITIAL LINE TO lt_report ASSIGNING <fs_rep>.
IF <fs_rep1>-um01s > <fs_rep1>-um01h.
<fs_rep>-jan_deb = <fs_rep1>-um01s - <fs_rep1>-um01h.
ELSE.
<fs_rep>-jan_cred = <fs_rep1>-um01h - <fs_rep1>-um01s.
ENDIF.
IF <fs_rep1>-um02s > <fs_rep1>-um02h.
<fs_rep>-feb_deb = <fs_rep1>-um02s - <fs_rep1>-um02h.
ELSE.
<fs_rep>-feb_cred = <fs_rep1>-um02h - <fs_rep1>-um02s.
ENDIF.
ENDLOOP.
repid = sy-repid.
*Build field catalog
wa_fieldcat-fieldname = 'JAN_DEB'. " Fieldname in the data table
wa_fieldcat-seltext_l = 'deb'. " ColuAN_DEBmn description in the output
wa_fieldcat-col_pos = 1.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'JAN_CRED'.
wa_fieldcat-seltext_l = 'cred'.
wa_fieldcat-col_pos = 1.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'FEB_DEB'. " Fieldname in the data table
wa_fieldcat-seltext_l = 'deb'. " Column description in the output
wa_fieldcat-col_pos = 2.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'FEB_CRED'.
wa_fieldcat-seltext_l = 'cred'.
wa_fieldcat-col_pos = 2.
APPEND wa_fieldcat TO it_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = repid
i_callback_user_command = 'HANDLE_USER_COMMAND'
i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'
it_fieldcat = it_fieldcat
TABLES
t_outtab = lt_report
EXCEPTIONS
program_error = 1
OTHERS = 2.
FORM html_top_of_page USING lw_document TYPE REF TO cl_dd_document .
DATA : doctable TYPE REF TO cl_dd_table_element,
col1_t1 TYPE REF TO cl_dd_area,
col2_t1 TYPE REF TO cl_dd_area.
*add quick table with five columns
CALL METHOD lw_document->add_table
EXPORTING
no_of_columns = 12
border = '1'
with_heading = 'X'
width = '150%'
IMPORTING
table = doctable.
*Filling columns in row
CALL METHOD doctable->add_column
EXPORTING
width = '8%'
IMPORTING
column = col1_t1.
*Filling columns in row
CALL METHOD doctable->add_column
EXPORTING
width = '8%'
IMPORTING
column = col2_t1.
CALL METHOD doctable->new_row.
CALL METHOD col1_t1->add_text
EXPORTING
text = 'JAN'.
CALL METHOD col2_t1->add_text
EXPORTING
text = 'FEB'.
ENDFORM. "html_top_of_page
As you can see I am trying to use html_top_of_page but the main headings are at the top and not inline with the subheadings. I know you can also use alv_list_display but I need grid display in-order to use filtering and sorting on the subheadings. The main headings does not need to use filtering or sorting or any other but they need to be on top of the subheadings and be inline with them where each heading should occupy two sub headings. It is possible to use one row scroll for the whole report? Also it is better if the main headings are self centered. How to achieve this?
I have a program which has a checkbox and if the user enable it runs the program in background with the below code:
REPORT zfile_creation_app2.
*&---------------------------------------------------------------------*
*& Create file on Application Server
*& if the file exist, it will be deleted and created with new content
*&---------------------------------------------------------------------*
TABLES : sflight.
TYPES: BEGIN OF ty_sflight,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
fldate TYPE sflight-fldate,
END OF ty_sflight.
DATA: lv_file(255).
DATA: lt_sflight TYPE TABLE OF ty_sflight.
FIELD-SYMBOLS: <fs_sflight> LIKE LINE OF lt_sflight.
"-----------------------------------------"
" Selection Screen
"-----------------------------------------"
SELECT-OPTIONS: s_carid FOR sflight-carrid,
s_fldte FOR sflight-fldate.
" File Path on Application Server
PARAMETERS: p_path TYPE btcxpgpar DEFAULT '/tmp',
p_bckgrd(1) TYPE c DEFAULT 'X'.
"-----------------------------------------"
" Help Search for SAP Folder
"-----------------------------------------"
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
DATA: c_fnh_mask TYPE dxfields-filemask VALUE '*',
search_dir TYPE dxfields-longpath.
CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = search_dir
filemask = c_fnh_mask
IMPORTING
serverfile = p_path
EXCEPTIONS
canceled_by_user = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
"-----------------------------------------"
" Processing
"-----------------------------------------"
START-OF-SELECTION.
IF p_bckgrd = 'X'.
PERFORM start_in_background.
ELSE.
PERFORM get_data.
PERFORM extract_to_file.
ENDIF.
END-OF-SELECTION.
WRITE: lv_file , ' is created' .
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_data .
SELECT carrid connid fldate FROM sflight INTO TABLE lt_sflight
WHERE carrid IN s_carid[] AND
fldate IN s_fldte.
IF sy-subrc NE 0 .
RETURN.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form EXTRACT_TO_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM extract_to_file .
" Build FineName
CONCATENATE p_path '/' 'Flight' sy-datum sy-uzeit '.txt' INTO lv_file.
REPLACE ALL OCCURRENCES OF '//' IN lv_file WITH '/'.
" Check if File exists
OPEN DATASET lv_file FOR INPUT IN BINARY MODE.
IF sy-subrc EQ 0.
" If File Exists -> Delete it
CLOSE DATASET lv_file.
DELETE DATASET lv_file.
CLOSE DATASET lv_file.
ENDIF.
" Open file for Output
OPEN DATASET lv_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0 .
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
" Transfer Data to file
LOOP AT lt_sflight ASSIGNING <fs_sflight>.
TRANSFER <fs_sflight> TO lv_file .
ENDLOOP.
" Close File
CLOSE DATASET lv_file.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form START_IN_BACKGROUND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM start_in_background .
DATA: d_jobcount LIKE tbtcjob-jobcount,
d_jobname LIKE tbtcjob-jobname.
d_jobname = 'ZFILE_CREATION_APP2'.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = d_jobname
IMPORTING
jobcount = d_jobcount
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc NE 0.
MESSAGE s368(00) WITH 'Error Creating Job'
sy-subrc.
EXIT.
ENDIF.
SUBMIT zfile_creation_app2
WITH s_carid = s_carid
WITH s_fldte = s_fldte
WITH p_bckgrd = space
WITH p_path = p_path
VIA JOB d_jobname
NUMBER d_jobcount
AND RETURN.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = d_jobcount
jobname = d_jobname
strtimmed = 'X' " Immediate
EXCEPTIONS
invalid_startdate = 1
jobname_missing = 2
job_close_failed = 3
job_nosteps = 4
job_notex = 5
lock_failed = 6
OTHERS = 7.
IF sy-subrc > 0.
MESSAGE s368(00) WITH 'Closing Job Failed'
sy-subrc.
EXIT.
ENDIF.
ENDFORM.
Unfortunately the background job always canceling with the following error:
Enter date in the format __.__.____
This is the default setup for the user.
Can anyone know what cause the problem and how to fix it?
Thanks in advance
Elias
The problem is with so_budat. If your so_budat is a select option try using "in" instead of "=". See below.
so_budat IN so_budat.
I can read all text from a text file(*.txt) using readalltext function in VB, but I want to split the text in other textboxes and one text file contains data and I want to split it, my text file is next:
x=first name
y=last name
z=age
And I want the code which can manage read data from that text file and after that split data in three textboxes like that.
textbox1.text=x
textbox2.text=y
textbox3.text=z
and last output was that
textbox1.text=first name
textbox2.text=last name
textbox3.text=age
So my problem is next: I want the code that can read x, y and z values from one text file.
Here's an example of code :
For Each line In File.ReadAllLines(file)
Select Case True
Case line.StartsWith("x=")
TextBox1.Text = line.Split("=")(1)
Case line.StartsWith("y=")
TextBox2.Text = line.Split("=")(1)
Case line.StartsWith("z=")
TextBox3.Text = line.Split("=")(1)
End Select
Next
Consider loading the contents into a List(Of String()):
Dim lst = File.ReadAllLines("filename.txt").Select(Function(line) line.Split("=")).ToList
Then if you store your textboxes in a List(Of TextBox), you could fill the corresponding textboxes appropriately:
For i = 0 To lst.Count
textboxes(i).Text = lst(i)(1)
Next
OK, so I have a file with three lines. I want a program to read from these lines and print the info.
Here's what I have so far:
print("Which user do you want to view?")
account = read()
file = io.open(account, "r")
name = io.read()
owe = io.read()
balance = io.read()
print("Their name is " .. name .. ".")
print("They owe us " .. owe .. ".")
print("They have " .. balance .. " in their account.")
When i run the program, it doesn't even come up with an error, just nothing happens. I have no idea what's going wrong...
io.read() reads from the current input file. By default, it's the standard input. You need to change it using io.input().
--...
f = io.open(account, "r")
io.input(f) # here
name = io.read()
owe = io.read()
balance = io.read()
--...
Another option is specify where to read from explicitely:
--...
f = io.open(account, "r")
name = f:read()
owe = f:read()
balance = f:read()
--...